package com.staryea.invocate.config;

import lombok.Data;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @Auther: hs
 * @Date: 2019/3/8 15:54
 * @Description:
 */
@Configuration
@EnableConfigurationProperties(HBaseConfig.HbaseProperties.class)
public class HBaseConfig {

    private static final String HBASE_PREFIX = "hbase";

    private final HbaseProperties PROPERTIES;

    public HBaseConfig(HbaseProperties properties) {
        this.PROPERTIES = properties;
    }

    public org.apache.hadoop.conf.Configuration configuration() {
        org.apache.hadoop.conf.Configuration configuration = HBaseConfiguration.create();
        Map<String, String> config = PROPERTIES.getConfig();
        config.forEach((key, value) -> configuration.set(key, value));
        return configuration;
    }

    /*@Bean
    public HbaseTemplate hbaseTemplate(){
        HbaseTemplate hbaseTemplate = new HbaseTemplate();
        hbaseTemplate.setConfiguration(configuration());
        hbaseTemplate.setAutoFlush(true);
        return  hbaseTemplate;
    }*/

    @Data
    @ConfigurationProperties(prefix = HBASE_PREFIX)
    public static class HbaseProperties {
        private Map<String, String> config;
    }


}
